package logic

import (
	"context"
	"errors"
	"goods_srv/models/mysqlinit"

	"goods_srv/goods"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DelHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDelHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelHouseLogic {
	return &DelHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DelHouseLogic) DelHouse(in *goods.DelHouseRequest) (*goods.DelHouseResponse, error) {
	// todo: add your logic here and delete this line
	var house mysqlinit.House
	mysqlinit.DB.Debug().Where("user_id = ?", in.UserId).Find(&house)
	if house.UserId != int(in.UserId) {
		logx.Error("无法删除他人房源")
		return nil, errors.New("无法删除他人房源")
	}
	mysqlinit.DB.Debug().Where("id = ?", in.Id).Delete(&mysqlinit.House{})

	return &goods.DelHouseResponse{
		//Id: int64(house.ID),
	}, nil
}
